﻿$(document).ready(function () {

    var bro = $.browser;
    var binfo = "";
    if (bro.msie) { binfo = "Microsoft Internet Explorer " + bro.version; }
    if (bro.mozilla) { binfo = "Mozilla Firefox " + bro.version; }
    if (bro.safari) { binfo = "Apple Safari " + bro.version; }
    if (bro.opera) { binfo = "Opera " + bro.version; }
    $("#browser").html(binfo + "123");

    $("#submit").click(function () {
        var uName = $("input[name='login']").val();
        var pwd = $("input[name='password']").val();
        var options = {
            type: "POST",
            url: "confirm.asmx/CheckUser",
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            data: '{"userName":"' + uName + '","pwd":"' + pwd + '"}',
            success: function (response) {
                if (response != null) {
                    if (response.d == "Succsee") {
                        //$("#userName").val(uName);
                        location.href = "ASP/BookingManage.aspx";
                    }
                    else {
                        alert(response.d);
                    }
                }
            },
            error: function (result, status) { //如果没有上面的捕获出错会执行这里的回调函数
                alert(status);
            }
        };
        $.ajax(options);
    })


    $("input[name='login']").keydown(function () {
        if (window.event.keyCode == 13) {
            $("input[name='password']").focus();
        }
    })
    $("input[name='password']").keydown(function(){
        if (window.event.keyCode == 13) {
            $("#submit").click();
        }
    })

    $("input[name='login']").blur(function () {
        var uName = $("input[name='login']").val();
        if (uName == "" || uName == null) {
            return;
        }
        var options = {
            type: "POST",
            url: "confirm.asmx/CheckUserName",
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            data: '{"userName":"' + uName + '"}',
            success: function (response) {
                if (response != null) {
                    if (response.d > 0) {
                    }
                    else {
                        alert("您输入的用户名不存在，请重新输入");
                        $("input[name='login']").attr("value",""); 
                        $("input[name='password']").attr("value", "");
                        return;
                    }
                }
            },
            error: function (result, status) {
                alert(status);
            }
        };
        $.ajax(options);
    });


})